package com.mall.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.mall.user.entity.param.PermissionAddParam;
import com.mall.user.entity.param.PermissionEditParam;
import com.mall.user.entity.po.Permission;
import com.mall.user.entity.vo.PermissionVO;
import com.mall.user.mapper.PermissionMapper;
import com.mall.user.service.IPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wuyijie
 * @since 2021-06-20
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public PermissionVO add(PermissionAddParam permissionAddParam) {
        PermissionVO add = null;
        permissionMapper.insert(BeanUtil.toBean(permissionAddParam, Permission.class));
        add = BeanUtil.toBean(permissionAddParam, PermissionVO.class);
        return add;
    }

    @Override
    public int deleteById(int id) {
        int delete;
        delete = permissionMapper.deleteById(id);
        return delete;
    }

    @Override
    public PermissionVO edit(PermissionEditParam permissionEditParam) {
        PermissionVO edit = null;
        permissionMapper.updateById(BeanUtil.toBean(permissionEditParam, Permission.class));
        edit = BeanUtil.toBean(permissionEditParam, PermissionVO.class);
        return edit;
    }

    @Override
    public PermissionVO queryById(int id) {
        PermissionVO permissionVO = null;
        Permission permission = permissionMapper.selectById(id);
        permissionVO = BeanUtil.toBean(permission, PermissionVO.class);
        return permissionVO;
    }
}
